﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;

namespace Tetris_Online___Client
{
    class Basic
    {
        public static Game1 game;
        public static GraphicsDevice gDevice;
        public static GraphicsDeviceManager gManager;
        public static SpriteBatch spriteBatch;
        public static ContentManager cManager;
        public static GameTime gameTime;

        public static int Width = 1280;
        public static int Height = 720;
        public static Rectangle Window = new Rectangle(0, 0, Width, Height);

        public static Screen currentScreen; 

        public static void Initialize(Game1 _game)
        {
            game = _game;
            gManager = _game.graphics;
            gDevice = _game.GraphicsDevice;
            cManager = _game.Content;
            spriteBatch = new SpriteBatch(gDevice);

            gManager.PreferredBackBufferHeight = Height;
            gManager.PreferredBackBufferWidth = Width;
            gManager.ApplyChanges();

            currentScreen = new ScreenManager.MenuScreen(); //NO SCREEN SELECTED
        }

        public static void LoadContent(ContentManager content)
        {
            Font.LoadContent(content);
            Texture.LoadContent(content);
            currentScreen.LoadContent(content);
        }

        public static void UnloadContent(ContentManager content)
        {
            Font.UnloadContent(content);
            Texture.UnloadContent(content);
            currentScreen.UnloadContent(content);
        }

        public static void Update(GameTime _gameTime)
        {
            gameTime = _gameTime;
            currentScreen.Update();
        }

        public static void Render2D()
        {
            spriteBatch.Begin();
            currentScreen.Render2D();
            spriteBatch.End();
        }

        public static void setScreen(Screen _screen)
        {
            currentScreen.UnloadContent(cManager);
            currentScreen = _screen;
            _screen.Initialize();
        }
    }
}
